﻿<cfsilent>

	<cfset jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice") />
	<cfset response = structNew() />

	<cftransaction>
	
		<!--- 更新行政班 教学计划属性 --->
		<cfset sql = "	SELECT
							p.p_id,p.cidx
						FROM
							t_plan p
						WHERE
							p.p_id = :planId " />

        <cfset queryObj = new Query( datasource=application.dnsMaster ) />
		
		<cfset queryObj.addParam( name="planId", value=event.getArg("PID"), cfsqltype="cf_sql_varchar" )/>
       
        <cfset rs_planEntity = queryObj.execute( sql=sql ).getResult()/>
        
		<cfswitch expression="#event.getArg('prop')#">
			
			<cfcase value="ForCourse">
				<!--- 修改班级排课课序号 --->
				<cfif yesNoFormat(event.getArg('status'))>
						<cfif rs_planEntity.cidx eq "XXX">
                           	<cfset sql = "	UPDATE
												t_plan p
												SET
												   p.cidx = :courseIndex 
											WHERE
												p.p_id = :planId " />

							<cfset queryObj = new Query( datasource=application.dnsMaster ) />
                            
                            <cfset queryObj.addParam( name="planId", value=event.getArg("PID"), cfsqltype="cf_sql_varchar" )/>
                            <cfset queryObj.addParam( name="courseIndex", value="000", cfsqltype="cf_sql_char" )/>
                           
                            <cfset queryObj.execute( sql=sql ) />
                            
						</cfif>
					<cfelse>
                        <cfset sql = "	UPDATE
												t_plan p
											SET
											   	p.cidx = :courseIndex 
											WHERE
												p.p_id = :planId " />

						<cfset queryObj = new Query( datasource=application.dnsMaster ) />
                            
                        <cfset queryObj.addParam( name="planId", value=event.getArg("PID"), cfsqltype="cf_sql_varchar" )/>
                        <cfset queryObj.addParam( name="courseIndex", value="XXX", cfsqltype="cf_sql_char" )/>
                           
                        <cfset queryObj.execute( sql=sql ) />
				</cfif>
			</cfcase>
						
		</cfswitch>
		
		<cfset sql = "	SELECT
							p.p_id,p.cidx
						FROM
							t_plan p
						WHERE
							p.p_id = :planId " />
        
        <cfset queryObj = new Query( datasource=application.dnsMaster ) />
		
		<cfset queryObj.addParam( name="planId", value=event.getArg("PID"), cfsqltype="cf_sql_varchar" )/>
       
        <cfset rs_planEntity = queryObj.execute( sql=sql ).getResult()/>

		<cfset structInsert(response, "PlanID", rs_planEntity.p_id) />
		<cfset structInsert(response, "CourseIndex", rs_planEntity.cidx) />

	</cftransaction>

</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>